var maxSla = {
    RENT_WITH_DRIVER : 1000*120,
    RENT_NO_DRIVER : 1000*120,
    TRAVEL_RENT : 1000*120,
    GO_AIRPORT : 1000*120,
    OFF_AIRPORT : 1000*120,
    PIECE : 1000*60*10
};

//online drivers information cache
var drivers = {};
//orders which are not token
var orders = {};
//online drivers sockets
var sockets = {};
//customer sockets
var customers = {
    // id : socket
};

function notify(id) {
    console.log("Notify All Drivers. ORDER : " + id);
    for(var i in sockets){
        if(drivers[i].status) {
            sockets[i].emit("getOrder",orders[id]);
            console.log("Notified :" + i +", ORDER :" + id);
        }
    }
}

module.exports = {
    drivers :drivers,
    orders : orders,
    sockets : sockets,
    customers : customers,
    handOutOrder : function(id){
        notify(id);
        setTimeout(function(){
            if(!!orders[id]) {
                orders[id].emergency = true;
                notify(id);
                //todo notify total account
            }
        },maxSla[orders[id].order_type]);
    },
    handOutToDriver : function(id) {
        for(var i in orders) {
            if(!!orders[i]) {
                sockets[id].emit("getOrder",orders[i]);
            }
        }
        console.log("Initial Emit");
    }


};